<template>
  <div class="page page-center-home">
    <head-bar title="个人中心" :prevRoute="{name: 'home'}"  />
    <section class="info-box">
      <div class="avatar"><img :src="userInfo.headImagerUrl ? userInfo.headImagerUrl : require('@/assets/images/avatar.png')"></div>
      <div class="info">
        <div class="name">{{userInfo.nickname}}</div>
        <div class="age-box">
          <span class="icon-gender man"></span>
          <span class="age">{{birthday | age}}岁</span>

        </div>
        <div>信用值：{{creditValue}}分</div>
      </div>
    </section>
    <van-cell-group class="menu-list">
      <van-cell title="个人信息" is-link icon="personal" :to="{name: 'user-info'}" />
      <van-cell title="我的预定" is-link icon="order" :to="{name: 'user-orders'}" />
      <van-cell title="关于我们" is-link icon="about" :to="{name: 'user-about'}" />
    </van-cell-group>
  </div>
</template>

<script>
import { Cell, CellGroup } from 'vant'
import { mapGetters } from 'vuex'
import dayjs from 'dayjs'
import { API_USERINFO } from '@/service/user'
import { wxjsdkMixin } from '@/components/mixins'
export default {
  mixins: [wxjsdkMixin],
  name: 'user-home',
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup
  },
  data () {
    return {
      creditValue: 0,
      birthday: ''
    }
  },
  computed: {
    ...mapGetters({ userInfo: 'getUserInfo' })
  },
  filters: {
    age (val) {
      return val ? dayjs(new Date()).diff(dayjs(val), 'year') : ''
    }
  },
  mounted () {
    this.wechatHideMenu()
    this.requestData()
  },
  methods: {
    requestData () {
      API_USERINFO().then((resData) => {
        let info = resData.info
        this.creditValue = info.creditValue
        this.birthday = info.birthDate
      })
    }
  }
}
</script>

<style lang="less">
.page-center-home{
  @images: "../../assets/images/user";

  .van-nav-bar{
    background: none;
    &:after{
      display: none;
    }

    .van-icon,.van-nav-bar__text{
      color: #fff!important;
    }
  }
  .info-box{
    background: url("@{images}/banner.jpg") no-repeat center/cover;
    display: flex;
    padding-top: 80px;
    padding-bottom: 90px;
    .avatar {
      width: 115/2px;
      height: 115/2px;
      margin-right: 15px;
      margin-left: 30px;
      border-radius: 50%;
      overflow: hidden;
      img{
        display: block;
        width: 100%;
        height: 100%;
      }
    }
    .info{
      color: #fff;

      .name {
        font-size: 18px;
        line-height: 23px;
      }
      .age-box{
        display: flex;
        align-items: center;
      }
      .icon-gender{
        display: inline-block;
        width: 12px;
        height: 13px;
        background-size: contain;
        background-position: center center;
        background-repeat: no-repeat;
        margin-right: 13px;

        &.man{
           background-image: url("@{images}/icon_man.png");
        }
        &.woman{
           background-image: url("@{images}/icon_woman.png");
        }
      }
      .age {
        font-size: 15px;
        line-height: 23px;
      }
    }
  }
  .menu-list{
    border-radius: 10px 10px 0 0;
    background-color: #fff;
    padding-top: 30px;
    margin-top: -30px;
    &:after{
      display: none;
    }
    .van-cell__title{
      font-weight: bold;
      font-size: 15px;
    }
    .van-icon{
      width: 20px;
      height: 20px;
      background-size: contain;
      background-position: center center;
      background-repeat: no-repeat;

      &-personal{
        background-image: url("@{images}/icon_personal.png");
      }
      &-order{
        background-image: url("@{images}/icon_order.png");
      }
      &-flag{
        background-image: url("@{images}/icon_flag.png");
      }
      &-board{
        background-image: url("@{images}/icon_board.png");
      }
      &-about{
        background-image: url("@{images}/icon_about.png");
      }
    }
  }
}
</style>
